<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='hblx' /></label>
                        <div class="layui-input-inline">
                            <select name="distributorScope">
                                <option value=""><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.type == 1}">selected</c:if>><fmt:message key='lx' /></option>
                                <option value="2" <c:if test="${params.type == 2}">selected</c:if>><fmt:message key='sp' /></option>
                                <option value="3" <c:if test="${params.type == 3}">selected</c:if>><fmt:message key='wd' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='zt' /></label>
                        <div class="layui-input-inline">
                            <select name="distributorScope">
                                <option value=""><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.status == 1}">selected</c:if>><fmt:message key='ysj' /></option>
                                <option value="2" <c:if test="${params.status == 2}">selected</c:if>><fmt:message key='yxj' /></option>
                                <option value="3" <c:if test="${params.status == 3}">selected</c:if>><fmt:message key='dtj' /></option>
                                <option value="4" <c:if test="${params.status == 4}">selected</c:if>><fmt:message key='dshenh' /></option>
                                <option value="5" <c:if test="${params.status == 5}">selected</c:if>><fmt:message key='shbtg' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='xzhb' /></a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="enables"><i class="layui-icon">&#x1006;</i><fmt:message key='plsj' /></a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="disables"><i class="layui-icon">&#x1006;</i><fmt:message key='plxj' /></a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="removes"><i class="layui-icon">&#x1006;</i><fmt:message key='plsc' /></a>

            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                    <th><fmt:message key='xh' /></th>
                    <th><fmt:message key='nr' /></th>
                    <th><fmt:message key='sm' /></th>
                    <th><fmt:message key='leixing' /></th>
                    <th><fmt:message key='cjrq' /></th>
                    <th><fmt:message key='zt' /></th>
                    <th><fmt:message key='cz' /></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${status.index + 1}</td>
                        <td><img style="width:40px; height:40px;" class="preview" src="${store_domain}/uploads/${item.image}"/></td>
                        <td>${item.content}</td>
                        <td>
                            <c:if test="${item.type == 1}"><fmt:message key='lx' /></c:if>
                            <c:if test="${item.type == 2}"><fmt:message key='sp' /></c:if>
                            <c:if test="${item.type == 3}"><fmt:message key='wd' /></c:if>
                        </td>
                        <td><fmt:formatDate value="${item.createTime}" type="both"/></td>
                        <td>
                            <c:if test="${item.status == 1}"><fmt:message key='ysj' /></c:if>
                            <c:if test="${item.status == 2}"><fmt:message key='yxj' /></c:if>
                            <c:if test="${item.status == 3}"><fmt:message key='dtj' /></c:if>
                            <c:if test="${item.status == 4}"><fmt:message key='dshenh' /></c:if>
                            <c:if test="${item.status == 5}"><fmt:message key='shbtg' /></c:if>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <c:if test="${item.status == 1}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-warm layui-btn-xs disable"><fmt:message key='xj' /></a>
                                </c:if>

                                <c:if test="${item.status == 2}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs enable"><fmt:message key='sj' /></a>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs remove"><fmt:message key='sc' /></a>
                                </c:if>

                                <c:if test="${item.status == 3}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs applyCheck"><fmt:message key='tjsh' /></a>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs modify"><fmt:message key='bj' /></a>
                                </c:if>

                                <c:if test="${item.status == 5}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs applyCheck"><fmt:message key='tjsh' /></a>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs modify"><fmt:message key='bj' /></a>
                                    <a href="javascript:void(0);" data-note="${item.note}" class="layui-btn layui-btn-xs note"><fmt:message key='ckjg' /></a>
                                </c:if>

                                <c:if test="${item.status != 4}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs remove"><fmt:message key='yc' /></a>
                                </c:if>

                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='xq' /></a>
                            </div>
                        </td>

                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    layui.use(['form', 'layer'], function () {

        var layer = layui.layer;
        var form = layui.form;

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });

        //添加海报
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjhb' />'
                , content: '${web_domain}/distribution/poster/create'
                , maxmin: true
                , area: ['92%', '92%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //查看
        $(".feijin-detail").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2
                , title: '<fmt:message key='ckfxhb' />'
                , content: '${web_domain}/distribution/poster/detail?id=' + id
                , maxmin: true
                , area: ['90%', '90%']
                , btn: ['<fmt:message key='fh' />']
            });
        });

        //编辑海报
        $(".modify").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2
                , title: '<fmt:message key='bjhb' />'
                , content: '${web_domain}/distribution/poster/'+ id +'/modify'
                , maxmin: true
                , area: ['92%', '92%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //上架
        $(".enable").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrsjm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/enable",
                    data: {"id": id}
                });
            });
        });

        //下架
        $(".disable").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrxjm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/disable",
                    data: {"id": id}
                });
            });
        });

        //提交审核
        $(".applyCheck").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrtjshm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/applyCheck",
                    data: {"id": id}
                });
            });
        });

        //查看结果
        $(".note").click(function () {
            var note = $(this).attr("data-note");
            layer.msg(note);
        });

        //移除
        $(".remove").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrycghbm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/remove",
                    data: {"id": id}
                });
            });
        });

        //批量移除
        $("#removes").click(function () {
            var ids = [];
            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });
            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl' />');
                return false;
            }
            layer.confirm("<fmt:message key='qrjxzhbycm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/removes",
                    data: {"ids": ids.join(";")}
                });
            });
        });

        //批量上架
        $("#enables").click(function () {
            var ids = [];
            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });
            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl' />');
                return false;
            }
            layer.confirm("<fmt:message key='qrjxzhbsjm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/enables",
                    data: {"ids": ids.join(";")}
                });
            });
        });

        //批量下架
        $("#disables").click(function () {
            var ids = [];
            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });
            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl' />');
                return false;
            }
            layer.confirm("<fmt:message key='qrjxzhbxjm' />", function () {
                feijin.put({
                    url: "${web_domain}/distribution/poster/disables",
                    data: {"ids": ids.join(";")}
                });
            });
        });

    });

</script>
</body>
</fmt:bundle>
</html>
